//
//  ZLStatusViewModel.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/27/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit

class ZLStatusViewModel: NSObject {

    var avatarImage: UIImage?
    var menberImage: UIImage?
    var iconURL: URL?
    var pictureInfo: [ZLPicture]?
    
    var status: ZLStatus? {
        
        didSet {
         
            dealIconURL()
            dealAvatarImge()
            dealMenberImage()
            
          pictureInfo = status?.retweeted_status == nil ? status?.pic_urls : status?.retweeted_status?.pic_urls
            
        }
    }
    
    
//    private func getPictureInfo() ->  {
//        
//        
//        
//    }
    
    
    private func dealAvatarImge() {
        
        let num = status?.user?.verified_type ?? -1
        
        
        
        switch num {
        case 0:
            avatarImage = #imageLiteral(resourceName: "avatar_vip")
        case 2,3,5:
            avatarImage = #imageLiteral(resourceName: "avatar_enterprise_vip")
            
        case 220:
            avatarImage = #imageLiteral(resourceName: "avatar_grassroot")
        default:
            
            avatarImage = nil
        }
    }
    
    private func dealMenberImage() {
    
        if let mbrank = status?.user?.mbrank, mbrank > 0 && mbrank < 7 {
            
            let imageName = "common_icon_membership_level\(mbrank)"
            
      
            menberImage = UIImage.init(named: imageName)
            
            return 
        }
//        menberImage = #imageLiteral(resourceName: "common_icon_membership_expired")
        
    }
    
    private func dealIconURL() {
        
        let urlString = status?.user?.avatar_large ?? ""
        
        iconURL = URL(string: urlString)
        
    }
}
